package service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import entity.LayRequest;
import entity.Log;
import mapper.LogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class LogServiceImpl implements LogService {
    @Autowired
    private LogMapper logMapper;

    @Override
    public boolean insert(Log log) {
        log.setOperation_time(new Date());
        return logMapper.insert(log)>0;
    }

    @Override
    public boolean deleteByTime(String end) {
        return logMapper.deleteByTime(end)>0;
    }

    @Override
    public boolean deleteAll() {
        return logMapper.deleteAll()>0;
    }

    @Override
    public PageInfo<Log> selectByPage(LayRequest layRequest) {
        PageHelper.startPage(layRequest.getPage(),layRequest.getLimit());
        List<Log> logs = logMapper.selectByTime(layRequest.getParams());
        PageInfo<Log> logPageInfo = new PageInfo<>(logs);
        return logPageInfo;
    }
}